package com.service.impl;

import com.bean.entity.MainGoods;
import com.dao.MainGoodsMapper;
import com.service.MainGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 供应商主营商品信息实现
 */
@Service
public class MainGoodsServiceImpl implements MainGoodsService {

    //自动注入
    @Autowired
    MainGoodsMapper mainGoodsMapper;

    @Override
    public List<MainGoods> queryAll(MainGoods mainGoods) {
        return mainGoodsMapper.select(mainGoods);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(MainGoods mainGoods) throws Exception {
        //修改信息
        int i = mainGoodsMapper.insert(mainGoods);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("添加失败！");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int modify(MainGoods mainGoods) throws Exception {
        //修改信息
        int i = mainGoodsMapper.update(mainGoods);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("修改失败！");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int remove(MainGoods mainGoods) throws Exception {
        //修改信息
        int i = mainGoodsMapper.delete(mainGoods);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("删除失败！");
        }
    }
}
